package 矩阵.一维数组转二维数组;

/**
 * TODO
 *
 * @className: ywszzewsz
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-01 23:36
 **/
public class ywszzewsz {
    public static void main(String[] args) {
//       int[] original = {1,2,3};
//       int m = 1, n = 3;
        int[] original = {1,1,1,1};
        int m = 4, n = 1;
        System.out.println(construct2DArray(original, m, n));
    }
    public static int[][] construct2DArray(int[] original, int m, int n) {
        if(original.length != n*m  || n < original.length/m){
            return new int[][]{};
        }
        int[][] result = new int[m][n];
        //判断扫描了几行 以便后续定位原始数据中的数据
        int p = 0;
        for(int i = 0;i < m;++i){
            for(int j = 0;j < n; ++j){
                //记录第几个数
                result[i][j] = original[p++];
            }

        }
        return result;
    }
}
